package org.example.book.model;

import lombok.Data;
import org.example.book.enums.ResultStatus;

@Data
public class Result<T> {
    private ResultStatus code;//业务码,不是Http转态码
    private String errMsg;//错误信息,业务成功为空
    private T data;

    public static <T> Result success(T data){
        Result result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setData(data);
        return result;
    }
    public static  Result nologin(){
        Result result = new Result<>();
        result.setCode(ResultStatus.NOLOGIN);
        result.setErrMsg("用户未登录");
        return result;
    }
    public static Result fail(String msg){
        Result result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(msg);
        return result;
    }
    public static Result fail(ResultStatus resultStatus,String msg){
        Result result = new Result<>();
        result.setCode(resultStatus);
        result.setErrMsg(msg);
        return result;
    }
}
